package previous.Test_0306;

import java.util.Scanner;

/**
 * Created with Intellij IDEA
 * Description:
 * User: 星辰
 */
public class Blue_bridge {
    //小怂爱水洼
    static int m;
    static int n;
    static boolean[][] vis;
    static long ret=Integer.MIN_VALUE;
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
         n=scan.nextInt();
         m=scan.nextInt();
        int[][] dp=new int[n+1][m+1];
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <=m ; j++) {
                dp[i][j]=scan.nextInt();
            }
        }
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m ; j++) {
                vis=new boolean[n+1][m+1];
                if(dp[i][j]!=0 && vis[i][j]!=true){
                    ret=Math.max(dfs(dp,i,j),ret);
                }
            }
        }
        System.out.println(ret);
        scan.close();
    }
    static int[] dx={0,0,1,-1};
    static int[] dy={1,-1,0,0};
    public static long dfs(int[][] dp,int i,int j){
        vis[i][j]=true;
        long sum=dp[i][j];
        for (int k = 0; k < 4; k++) {
                int x=dx[k]+i;
                int y=dy[k]+j;
                if(x>=1 && x<=n && y>=1 && y<=m && dp[x][y]!=0 &&  vis[x][y]!=true){
                     sum+=dfs(dp,x,y);
                }
        }
        return sum;
    }

}
